package com.example.tiptravel.view.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.example.tiptravel.R;
import com.example.tiptravel.commom.base.BaseActivity;
import com.example.tiptravel.entity.home.spot.SpotEntity;
import com.example.tiptravel.presenter.home.SpotPresenter;
import com.example.tiptravel.view.adapter.SpotAdapter;
import com.example.tiptravel.view.impl.home.SpotView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

public class SpotActivity extends BaseActivity implements SpotView {


    @BindView(R.id.rclv_spot)
    RecyclerView rclvSpot;
    @BindView(R.id.iv_spot_back)
    ImageView ivSpotBack;
    private List<SpotEntity.DataBean> dataBeen = new ArrayList<>();
    private SpotAdapter adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_spot;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rclvSpot.setLayoutManager(new LinearLayoutManager(this));
        adapter = new SpotAdapter(dataBeen, this);
        rclvSpot.setAdapter(adapter);
        initData();
    }

    @Override
    protected void initData() {
        SpotPresenter presenter = new SpotPresenter(this);
        Map<String, String> map = new HashMap<>();
        map.put("version", "android_3.8.1");
        presenter.getSpotData(map);
    }

    @OnClick(R.id.iv_spot_back)
    public void onClick() {
        finish();
    }

    @Override
    public void onSuccess(SpotEntity spotEntity) {
        if (spotEntity != null && spotEntity.getStatus().equals("1")) {
            dataBeen.addAll(spotEntity.getData());
            adapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onFailure(Throwable e) {

    }

    @Override
    public void onComplete() {

    }

}
